﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;
using DevExpress.XtraEditors;
using log4net;

namespace MesgessSystem.Registered
{
    public partial class UserRegistered : Form
    {
        private static ILog _log = LogManager.GetLogger(typeof(Form));
        Mesgesssystem.DBHelper ds;
        string SqlText;
        public UserRegistered()
        {
            InitializeComponent();
        }

        /// <summary>
        /// 注册用户名按钮
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button1_Click(object sender, EventArgs e)
        {
            ds = new Mesgesssystem.DBHelper();
            SqlText = "select * from userinfo where usermane=@userID";
            DataSet dt = ds.DBselect(SqlText, new SqlParameter("@userID", txtName.Text));
            if (txtName.Text.Trim() == "")
            {
                //XtraMessageBox.Show("用户名不能为空，请输入！","提示");
                MessageBox.Show("用户名不能为空，请输入！", "提示");
                txtName.Focus();  //光标集中
            }
            else if (txtPassword.Text.Trim().Equals(string.Empty))
            {
                //XtraMessageBox.Show("密码不能为空，请输入！", "提示");
                MessageBox.Show("密码不能为空，请输入！", "提示");
            }
            else if (!txtPassword.Text.Trim().Equals(txtConfirm.Text.Trim()))
            {
                //XtraMessageBox.Show("两次密码不一致，请重新输入！", "提示");
                MessageBox.Show("两次密码不一致，请重新输入！", "提示");
            }
            else if (dt.Tables[0].Rows.Count != 0)
            {
                //XtraMessageBox.Show("用户名已经存在，请重新输入！", "提示");
                MessageBox.Show("用户名已经存在，请重新输入！", "提示");
            }
            else
            {
                SqlText = "insert into userinfo(usermane,userpassword) values(@userID,@userpassword)";
                ds = new Mesgesssystem.DBHelper();
                ds.DBinsert(SqlText, new SqlParameter("@userID", txtName.Text.Trim()), new SqlParameter("@userpassword",txtPassword.Text.Trim()));
                //XtraMessageBox.Show(" 注 册 成 功 ", "提示");    
                MessageBox.Show(" 注 册 用 户 成 功 ", "提 示");
                _log.Info(" 注 册 用 户 成 功 ");
            }
        }
        /// <summary>
        /// 关闭当前窗体
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void UserRegistered_Load(object sender, EventArgs e)
        {
            this.MaximizeBox = false;//禁止窗体最大化
        }
    }
}
